<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class pesanan_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insertpemesanan($data){
		$this->db->insert('pesanan',$data);
	}
	
	function insertpelanggan($data){
		$this->db->insert('konsumen',$data);
	}
	
	function getidpesan(){
	$query = $this->db->query("select max(id_pesanan) as id_pesanan from pesanan");
	return $query;
	
	}
	
	function descbarang($id_barang){
	$query = $this->db->query("select *  from barang where id_barang=".$id_barang."");
	return $query;
	
	}
	
	function inserttransaksi($data){
		$this->db->insert('transaksi',$data);
	}
	
	// mendapatkan master barang
	
	function get_data_barang(){
		//Select table name
		$this->db->select("*");
		$this->db->from('barang');
		$query = $this->db->get();
		return $query;
		
		
	}
	
	// get master konsumen
	function get_data_konsumen(){
		//Select table name
		$this->db->select("*");
		$this->db->from('konsumen');
		$query = $this->db->get();
		return $query;
		
		
	}
	
	//list flexy
	function get_data_m_pesanan(){
		//Select table name
		$this->db->select("*");
		$this->db->from('pesanan');
		//$this->db->join('m_negara k', 'k.id_negara = w.id_negara');
		$query = $this->db->get();
		
		return $query;
		
	}
	
	
	
	
	function delete($id){
		$this->db->where('id_pesanan', $id);
		$this->db->delete('m_pesanan');
	}
	
	function selectone($id){
		$this->db->select("*");
		$this->db->from('m_pesanan');
		$this->db->where('id_pesanan',$id);
		$query = $this->db->get();
		return $query;
	}
	
	function update($data,$id ){
		$this->db->where('id_pesanan',$id);
		$this->db->update('m_pesanan',$data);
	}
        
	function get_m_pesanan(){
		$this->db->select("*");
		$this->db->from('m_pesanan');
		$this->db->where("STATUS > 0 ");
		$query = $this->db->get();
		return $query;
	}
	
	
}

?>